package com.ldc.composelibs

import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.ldc.commonlibs.common.RspModel
import com.ldc.commonlibs.common.ViewModelBase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.withContext

open class ViewModelCompose : ViewModelBase() {

    suspend fun <T> apiCall(call: suspend CoroutineScope.() -> RspModel<T>): RspModel<T> {
        val data = try {
            withContext(Dispatchers.IO) {
                call()
            }
        } catch (e: Exception) {
            RspModel.fromException(e)
        }
        return data
    }


}